package CutLoad.cookies
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	/**
	 * 版权到期类
	 * 该类是用来检测是否到达某一个时间了。如果到了，就提示过期。
	 * 该类的用途是当给别人做的应用后，如果对方没有把尾款给你，就可以到时候会自动屏蔽。为防止破解，强烈建议用加密软件加密： SWF Encrypt
	 * @author smallerbird mail:smallerbird@gmail.com  site:www.mkigm.com QQ群:49983196
	 * 
	 */
	public class SWFReg extends Sprite
	{
		//还有多久
		private var sectendTime:Number=0;
		//
		private var txt:TextField;
		private var describe:String,youNoReg:String;
		private var _stage:Stage;
		/**
		 * 
		 * @param describe 显示的信息
		 * @param youNoReg 到期后显示的信息
		 * @param year 到期年
		 * @param month 到期月
		 * @param day 到期日
		 * 
		 */		
		public function SWFReg(stage:Stage,describe:String,youNoReg:String,year:Number,month:Number,day:Number)
		{
			//
			this._stage=stage;
			var now:Date=new Date();
			var today:Date=new Date(now.getFullYear(),now.getMonth(),now.getDate());
			var endTDtae:Date=new Date(year,month-1,day);
			sectendTime=Math.floor((endTDtae.getTime()-today.getTime())/1000);
			//trace(sectendTime)
			//
			if(describe==""){
				describe="测试版 ";
			}
			this.describe=describe;
			if(youNoReg==""){
				youNoReg="测试版已到期，请与服务商联系..";
			}
			this.youNoReg=youNoReg;
			//
			txt=getTxt();
			txt.text=describe+" "+sectendTime;
			this.addChild(txt);
			//
			this.addEventListener(Event.ENTER_FRAME,funEnterFrame);
		}
		//
		private var funEnterFrame_i:Number=0
		private function funEnterFrame(e:Event):void{
			if(funEnterFrame_i++>_stage.frameRate){
				funEnterFrame_i=0;
				sectendTime--;
				txt.text=describe+" -"+sectendTime;
				if(sectendTime<=0){
					var sp:Sprite=new Sprite();
					var gg:Graphics=sp.graphics;
					gg.beginFill(0xcccccc,0.8);
					gg.drawRect(0,0,_stage.stageWidth,_stage.stageHeight);
					gg.endFill();
					var txt123:TextField=getTxt();
					txt123.text=youNoReg;
					txt123.x=(_stage.stageWidth-txt123.textWidth)/2
					txt123.y=(_stage.stageHeight-txt123.textHeight)/2
					sp.addChild(txt123);
					_stage.addChild(sp);
					this.removeEventListener(Event.ENTER_FRAME,funEnterFrame)
				}
			}
		}
		//获和显示的文本框
		private function getTxt():TextField{
			var txt:TextField=new TextField();
			txt.autoSize=TextFieldAutoSize.LEFT;
			var txtFormat:TextFormat=new TextFormat();
			txtFormat.size=20;
			txtFormat.color=0xff0000;
			txtFormat.bold=true;
			txt.defaultTextFormat=txtFormat;
			return txt;
		}
	}
}